package cn.leida.ruoyi.web.controller.monitor;

import cn.leida.ruoyi.common.annotation.Log;
import cn.leida.ruoyi.common.core.controller.BaseController;
import cn.leida.ruoyi.common.core.domain.AjaxResult;
import cn.leida.ruoyi.common.core.page.TableDataInfo;
import cn.leida.ruoyi.common.enums.BusinessType;
import cn.leida.ruoyi.common.utils.poi.ExcelUtil;
import cn.leida.ruoyi.system.domain.SysLoginInfor;
import cn.leida.ruoyi.system.service.ISysLoginInforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 系统访问记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/monitor/logininfor")
public class SysLoginInforController extends BaseController {
    @Autowired
    private ISysLoginInforService loginInforService;

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLoginInfor logininfor) {
        Page<SysLoginInfor> page = loginInforService.selectLogininforList(logininfor);
        return getDataTable(page);
    }

    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')")
    @GetMapping("/export")
    public AjaxResult export(SysLoginInfor logininfor) {
        Page<SysLoginInfor> page = loginInforService.selectLogininforList(logininfor);
        ExcelUtil<SysLoginInfor> util = new ExcelUtil<SysLoginInfor>(SysLoginInfor.class);
        return util.exportExcel(page.getContent(), "登录日志");
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds) {
        return toAjax(loginInforService.deleteLogininforByIds(infoIds));
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean() {
        loginInforService.cleanLogininfor();
        return AjaxResult.success();
    }
}
